<!DOCTYPE html>
<html>
	{include file="public/_header" /}
	<body>
		<div class="x-nav">
			<span class="layui-breadcrumb">
				<a href="">首页</a>
				<a>
					<cite>备份管理</cite></a>
			</span>
			<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()"
			 title="刷新">
				<i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
		</div>
		<div class="layui-fluid">
			<div class="layui-row layui-col-space15">
				<div class="layui-col-md12">
					<div class="layui-card">
						<div class="layui-card-body ">
							<table class="layui-hide" id="test" lay-filter="test"></table>
						</div>
					</div>
				</div>
			</div>
		</div>

		<script type="text/html" id="barDemo">
			<a class="layui-btn layui-btn-xs" href="{:url('admin/Database/downfile')}?path={{d.path}}">下载</a>
			<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">{:lang('delete')}</a>
		</script>

		<script>
			function renderSize(value){
			    if(null==value||value==''){
			        return "0 Bytes";
			    }
			    var unitArr = new Array("Bytes","KB","MB","GB","TB","PB","EB","ZB","YB");
			    var index=0,
			        srcsize = parseFloat(value);
			 index=Math.floor(Math.log(srcsize)/Math.log(1024));
			    var size =srcsize/Math.pow(1024,index);
			    //  保留的小数位数
			    size=size.toFixed(2);
			    return size+unitArr[index];
			}
			layui.use(['table','util'], function() {
				var table = layui.table;
				var util = layui.util;
				var tableInfo = table.render({
					elem: '#test',
					url: "{:url('admin/Database/restore')}",
					cols: [
						[{
							field: 'filename',
							title: "文件名"
						},
						{
							field: 'filemtime',
							title: "修改时间",
							templet: function(d) {
								var logoSrc = util.toDateString(d.filemtime * 1000, "yyyy-MM-dd HH:mm:ss");
								return logoSrc;
							}
						},{
							field: 'fileatime',
							title: "创建时间",
							templet: function(d) {
								var logoSrc = util.toDateString(d.fileatime * 1000, "yyyy-MM-dd HH:mm:ss");
								return logoSrc;
							}
						},{
							field: 'size',
							title: "文件大小",
							templet:function(d){
								return renderSize(d.size);
							}
						}, {
							fixed: 'right',
							title: "{:lang('action')}",
							toolbar: '#barDemo',
							width: 130
						}]
					],
					page: true
				});
				//监听行工具事件
				table.on('tool(test)', function(obj) {
					var data = obj.data;
					//console.log(obj)
					if (obj.event === 'del') {
						parent.layer.confirm('真的删除行么', function(index) {
							$.post("{:url('admin/Database/dele')}",data,function(res){
								if(res.status == 1){
									parent.layer.msg('删除成功', {
										icon: 1,
										time: 300
									}, function() {
										layer.close(index);
										tableInfo.reload()
									});
								}else{
									parent.layer.msg(res.message,{
										icon: 5,
										time: 5000
									})
								}
							})
							
						});
					}
				});
				//监听单元格编辑
				table.on('edit(test)', function(obj) {
					var value = obj.value, //得到修改后的值
						data = obj.data, //得到所在行所有键值
						field = obj.field; //得到字段
						if(!check_validate1(value)){
							layer.msg('你必须输入数字');
							tableInfo.reload()
						}else{
							sort(obj,tableInfo)
						}
				});
			});
			function sort(obj,tableIns){
				$.post("{:url('admin/Banner/typesort')}",obj.data,function(res){
					if(res.status == 1){
						tableIns.reload()
					}
				})
			}
		</script>
	</body>
</html>
